package ah.encode;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;

public class TestURLDecoder {

	
	/**
	 * @param args
	 * @throws Exception 
	 */
	public static void main(String[] args) {
		try {
			String sss = new String("中文鎔".getBytes("gb2312"), "iso-8859-1");
			System.out.println(sss);
			String ttt = new String(new String(sss.getBytes("iso-8859-1"), "gb2312"));
			System.out.println(ttt);
			new TestURLDecoder().encodeOut();
			
			String a = "中文鎔";
			byte[] as = a.getBytes("utf-8");
			for (byte t : as) {
				System.out.print(Integer.toHexString(t)+" ");
			}
			System.out.println();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	/**
	 * 编码ＵＲＬ
	 * @throws Exception
	 */
	public void encodeURL() throws Exception {
		//javascript:encodeURI(this.href,"utf-8") 火狐会再次编码
		//解码超过两次就能还原了
		String str = "http://192.168.0.224/doctor.do?diseaseName=%E9%AB%98%E8%A1%80%E5%8E%8B&doctorArea=%E6%B5%99%E6%B1%9F";
		String str2 = URLDecoder.decode(str, "UTF-8");
		str2 = URLDecoder.decode(str2, "UTF-8");
		str2 = URLDecoder.decode(str2, "UTF-8");
		System.out.println(str2);
	}
	
	public void encodeOut() throws UnsupportedEncodingException {
		String a = "中文鎔";
		System.out.println(URLEncoder.encode(a, "utf-8"));
	}
}
